//package Test;
//
//import Common.DriverCommon;
//import Util.StringConvertToDouble;
//import org.neo4j.driver.*;
//import org.neo4j.driver.types.Node;
//
//
//import static org.neo4j.driver.Values.parameters;
//
//public class Neo4jNearRelation {
//    public static void main(String[] args) {
//        try (DriverCommon driverCommon = new DriverCommon()){
//            Driver driver = driverCommon.getGraphDatabase();
//            Session session = driver.session();
//            Session session2 = driver.session();
//            // 遍历所有 NorthDistrictPolygon 节点
//            try (Transaction tx = session.beginTransaction()){
//                Result result = tx.run("MATCH (n:NorthDistrictPolygon) RETURN n");
//
//                while (result.hasNext()) {
//                    Record record = result.next();
//                    Node node = record.get("n").asNode();
//                    String centerPoint =  String.valueOf(node.get("centerPoint"));
//                    CenterPointDTO c1 = StringConvertToDouble.convert(centerPoint);
//
//                    // 检查当前节点与其他节点的距离
//                    try (Transaction innerTx = session2.beginTransaction()) {
//                        Result innerResult = innerTx.run("MATCH (m:NorthDistrictPolygon) WHERE id(m) <> $currentNodeId " +
//                                " RETURN m", parameters("currentNodeId",node.id()));
//                        while (innerResult.hasNext()) {
//                            Record innerRecord = innerResult.next();
//                            Node node2 = innerRecord.get("m").asNode();
//                            String otherCenterPoint =  String.valueOf(node2.get("centerPoint"));
//                            CenterPointDTO c2 = StringConvertToDouble.convert(otherCenterPoint);
//
//                            // 计算节点之间的距离
////                            double distance = CalculateDistanceByCenterPointUtil.calculate(c1, c2);
////                            System.out.println("距离:  "+distance);
//
////                            // 如果距离小于200，添加或删除 "NEAR" 关系
////                            if (distance < 80) {
////                                // 添加 "NEAR" 关系
////                                innerTx.run("MATCH (n1), (n2) " +
////                                        " WHERE ID(n1) = $id1 AND ID(n2) = $id2" +
////                                        " AND NOT EXISTS((n1)-[:Near]-(n2)) " +
////                                        " AND NOT EXISTS((n2)-[:Near]-(n2)) " +
////                                        " CREATE (n1)-[:Near]->(n2) ",parameters("id1",node.id(),"id2",node2.id()));
////                                System.out.println("添加成功");
////                            } else {
//////                                // 删除 "NEAR" 关系
//////                                innerTx.run("MATCH (n)-[r:NEAR]-(m) DELETE r");
////                                System.out.println("不执行  删除   ");
////                            }
//                        }
//                        innerTx.commit();
//                    }
//                }
//                tx.commit();
//            }
//        }
//    }
//}
